//
//  ZQTools.m
//  chongwu
//
//  Created by 隼目 on 2021/9/16.
//

#import "ZQTools.h"
#import "NSString+CZNSStringExt.h"

@implementation ZQTools

#pragma mark———————————————— 计算文字高度
+ (CGSize)getNSStringSize:(NSString *)string andViewWight:(CGFloat)weight andFont:(NSInteger)font
{
    return  [string sizeOfTextWithMaxSize:CGSizeMake(weight, MAXFLOAT) font:[UIFont systemFontOfSize:font]];
    
}

#pragma mark———————————————— 跳转 push
+ (void)pushRootViewController:(UIViewController *)RootViewController andNextController:(UIViewController *)nextVc
{
    
    
    nextVc.hidesBottomBarWhenPushed = YES;
    
    [RootViewController.navigationController pushViewController:nextVc
                                                       animated:YES];
    
}
//判断字符是否为空
+(BOOL)charIsNil:(NSString *)str{
    
    if ([str isKindOfClass:[NSNull class]]||[str isEqualToString:@""]||str==nil) {
        return YES;
    }
    return  NO;
}

#pragma mark————————————————nsdate 转 时间搓
+ (NSString *)NSDateToTimeCuo:(NSDate *)date
{
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
    
    return timeSp;
}
#pragma mark——————————————————NSString转NSDate (年月日)
+ (NSDate *)NSStringToNSDate:(NSString *)DateFormat : (NSString *)dateStr
{
    //先获得开始时间
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:DateFormat];
    NSDate *date=[dateFormatter dateFromString:dateStr];
    return date;
}
#pragma mark——————————————转换时间锉 传入时间锉字符串  得到解析后的字符串
+ (NSString *)changeTimeCuo: (NSString *)DateFormat : (NSString *)time
{
    //如果带有网页标签 就先去掉
    if([time rangeOfString:@"/Date"].location !=NSNotFound)//_roaldSearchText
    {
        
        //去掉多余的字符
        NSString *timeString = [[time stringByReplacingOccurrencesOfString:@"/Date(" withString:@""] stringByReplacingOccurrencesOfString:@"000)/" withString:@""];
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:DateFormat];
        double timeInt =[timeString doubleValue];
        NSTimeZone *TimeZon=[NSTimeZone systemTimeZone];
        NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timeInt];
        formatter.locale=[[NSLocale alloc]initWithLocaleIdentifier:TimeZon.name];
        NSString *myNewDateString = [formatter stringFromDate:date1];
        return myNewDateString;
    }
    else
    {
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:DateFormat];
        //这里看后台返回的时间锉 长度是否为包含了毫秒级 如果返回了毫秒级 就／1000才能解析成正常的时间
        double timeInt =[time doubleValue];
        NSTimeZone *TimeZon=[NSTimeZone systemTimeZone];
        NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timeInt];
        formatter.locale=[[NSLocale alloc]initWithLocaleIdentifier:TimeZon.name];
        NSString *myNewDateString = [formatter stringFromDate:date1];
        return myNewDateString;
    }
}
#pragma mark——————————————当前时间格式
+(NSString *)changeTimeCuo: (NSString *)DateFormat{
    NSDateFormatter *formater = [[ NSDateFormatter alloc] init];
    NSDate *curDate = [NSDate date];//获取当前日期
    [formater setDateFormat:DateFormat];//这里去掉 具体时间 保留日期
    NSString * curTime = [formater stringFromDate:curDate];
    return curTime;
}
#pragma mark————————svp提醒
+ (void)svpInfo:(NSString *)title
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [FTIndicator setIndicatorStyle:UIBlurEffectStyleDark];
        [FTIndicator showToastMessage:title];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [FTIndicator dismissToast];
        });
    });
}
//手机号码
+ (BOOL)isMobileNumber:(NSString *)mobileNum {
    NSString *MOBILE = @"^1(3[0-9]|4[579]|5[0-35-9]|6[6]|7[0-35-9]|8[0-9]|9[89])\\d{8}$";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    return [regextestmobile evaluateWithObject:mobileNum];
}


@end
